<#include "../public/header.html">
    <div id="editdlg">
    </div>
    <div class="easyui-layout" style="width:100%;height:100%;">
        <div id="p" data-options="region:'west'" title="校区" style="width:20%;padding:10px">
            <ul id="tt" class="easyui-tree" data-options="url:'admin/department/combotree',method:'get',animate:true,onClick:tree_select"></ul>
        </div>
        <div data-options="region:'center'" title="用户列表">
            <div id="tb" style="padding:5px 5px; border-bottom: dashed #d2d2d2 1px;margin-bottom: 5px;">
                帐户: <input class="easyui-textbox" style="width:110px" id="code">
                名称: <input class="easyui-textbox" style="width:110px" id="name">
                <a href="javascript://" class="easyui-linkbutton" iconCls="icon-search" onclick="search_but()">搜索</a>
            </div>
            <table id="list" class="easyui-datagrid" style="width:100%;height:100%"
                   sortName="id"
                   sortOrder="asc"
                   rownumbers="true"
                   pagination="true"
                   pagesize="50"
                   singleSelect="true"
                   data-options="url:'admin/user/listJson',toolbar:toolbar">
                <thead>
                <tr>
                    <th field="code" width="100" sortable="true">帐户</th>
                    <th field="name" width="80" align="right" sortable="true">名称</th>
                    <th field="email" width="80" align="right" sortable="true">邮箱</th>
                    <th field="phone" width="80" align="right" sortable="true">联系方式</th>
                    <th field="role_name" width="100" align="right" sortable="true">角色</th>
                    <th field="dep_name" width="80" align="right" sortable="true">归属学校</th>
                    <th field="state" width="80" align="right" sortable="true">状态</th>
                    <th field="create_user" width="80" align="right" sortable="true">创建人</th>
                    <th field="create_datetime" width="80" align="right" sortable="true">创建时间</th>
                </tr>
                </thead>
            </table>


        </div>
    </div>


    <script type="text/javascript">
        var id ;
        var dep;
        $(function(){
            $("#tb").prependTo(".datagrid-toolbar");
        })
        var toolbar = [{
            id:20201,
            disabled:"${((permission_button.p20201!) == 'true')? string('','true')}",
            text:'添加',
            iconCls:'icon-add',
            handler:function(){
                $("#editdlg").dialog({
                    title:"添加",
                    iconCls: 'icon-edit',
                    width: 400,
                    height: 400,
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/user/edit",
                    onLoad:function() {
                        $.messager.progress('close');
                        if(dep !== undefined){
                            $("#dep").combotree("setValue",dep);
                        }
                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#editForm').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#editForm').form('submit',{
                                url:"admin/user/save",
                                dataType:"json",
                                onSubmit:function(){
                                    return $(this).form('enableValidation').form('validate');
                                },
                                success:function(data){
                                    var data = eval('(' + data + ')');  // change the JSON string to javascript object

                                    $.messager.alert("提示",data.msg);
                                    $("#editdlg").dialog("close");
                                    $("#list").datagrid("reload");
                                }
                            });
                        }
                    }]
                });
            }
        },{
            id:20202,
            disabled:"${((permission_button.p20202!) == 'true')? string('','true')}",
            text:'编缉',
            iconCls:'icon-edit',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择要编缉的行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

               $("#editdlg").dialog({
                   title:"编缉",
                   iconCls: 'icon-edit',
                   width: 400,
                   height: 400,
                   closed: false,
                   cache: false,
                   modal: true,
                   href:"admin/user/edit?id="+note.id,
                   onLoad:function() {
                       $.messager.progress('close');
                   },
                   buttons: [{
                       text: '取消',
                       iconCls:'icon-cancel',
                       handler: function () {
                           $('#editForm').form('clear');
                           $("#editdlg").dialog("close");
                       }
                   },{
                       text: '保存',
                       iconCls: 'icon-ok',
                       handler: function () {
                           $('#editForm').form('submit',{
                               url:"admin/user/save",
                               onSubmit:function(){
                                   return $(this).form('enableValidation').form('validate');
                               },
                               success:function(data){
                                   var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                   $.messager.alert("提示",data.msg);
                                   $("#editdlg").dialog("close");
                                   $("#list").datagrid("reload");
                               }
                           });
                       }
                   }]
               });
            }
        },'-',{
            id:10203,
            disabled:"${((permission_button.p10203!) == 'true')? string('','true')}",
            text:'角色',
            iconCls:'icon-grou',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

                $("#editdlg").dialog({
                    title:"角色",
                    iconCls: 'icon-edit',
                    width: 400,
                    height: 400,
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/role/load_user_role?user_id="+note.id,
                    onLoad:function() {
                        $.messager.progress('close');
                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#editUserRoleForm').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#editUserRoleForm').form('submit',{
                                url:"admin/role/save_user_role",
                                success:function(data){
                                    var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                    $.messager.alert('提示',data.msg);
                                    $("#editdlg").dialog("close");
                                    $('#editUserRoleForm').form('clear');
                                }
                            });
                        }
                    }]
                });
            }
        },{
            id:10204,
            disabled:"${((permission_button.p10204!) == 'true')? string('','true')}",
            text:'删除',
            iconCls:'icon-delete',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }else{
                    $.ajax({
                        type:"get",
		                url:"admin/user/detele?uid="+note.id,
                        dataType:"JSON",
		                success:function(data){
//		                    var data = eval('(' + data + ')');  // change the JSON string to javascript object
                            $.messager.alert('提示',data.msg);
		                    $("#list").datagrid("reload");
		                }
		            });
                }
            }
        }];

        function search_but(){
           $("#list").datagrid("reload",{code:$("#code").val(),name:$("#name").val()});
        }

        function tree_select(note){
            $("#list").datagrid("reload",{code:$("#code").val(),name:$("#name").val(),dep_id:note.id});
            dep = note.id;
        }
    </script>
    <#include "../public/footer.html">